home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / dbus / _dbus.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  9.3 KB  |  220 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Implementation for dbus.Bus. Not to be imported directly.'''
  5. from __future__ import generators
  6. __all__ = ('Bus', 'SystemBus', 'SessionBus', 'StarterBus')
  7. __docformat__ = 'reStructuredText'
  8. import os
  9. import sys
  10. import weakref
  11. from traceback import print_exc
  12. from dbus.exceptions import DBusException
  13. from _dbus_bindings import BUS_DAEMON_NAME, BUS_DAEMON_PATH, BUS_DAEMON_IFACE, UTF8String, validate_member_name, validate_interface_name, validate_bus_name, validate_object_path, BUS_SESSION, BUS_SYSTEM, BUS_STARTER, DBUS_START_REPLY_SUCCESS, DBUS_START_REPLY_ALREADY_RUNNING
  14. from dbus.bus import BusConnection
  15. from dbus.lowlevel import SignalMessage
  16.  
  17. try:
  18.     import thread
  19. except ImportError:
  20.     import dummy_thread as thread
  21.  
  22.  
  23. class Bus(BusConnection):
  24.     """A connection to one of three possible standard buses, the SESSION,
  25.     SYSTEM, or STARTER bus. This class manages shared connections to those
  26.     buses.
  27.  
  28.     If you're trying to subclass `Bus`, you may be better off subclassing
  29.     `BusConnection`, which doesn't have all this magic.
  30.     """
  31.     _shared_instances = { }
  32.     
  33.     def __new__(cls, bus_type = BusConnection.TYPE_SESSION, private = False, mainloop = None):
  34.         '''Constructor, returning an existing instance where appropriate.
  35.  
  36.         The returned instance is actually always an instance of `SessionBus`,
  37.         `SystemBus` or `StarterBus`.
  38.  
  39.         :Parameters:
  40.             `bus_type` : cls.TYPE_SESSION, cls.TYPE_SYSTEM or cls.TYPE_STARTER
  41.                 Connect to the appropriate bus
  42.             `private` : bool
  43.                 If true, never return an existing shared instance, but instead
  44.                 return a private connection.
  45.  
  46.                 :Deprecated: since 0.82.3. Use dbus.bus.BusConnection for
  47.                     private connections.
  48.  
  49.             `mainloop` : dbus.mainloop.NativeMainLoop
  50.                 The main loop to use. The default is to use the default
  51.                 main loop if one has been set up, or raise an exception
  52.                 if none has been.
  53.         :Changed: in dbus-python 0.80:
  54.             converted from a wrapper around a Connection to a Connection
  55.             subclass.
  56.         '''
  57.         if not private and bus_type in cls._shared_instances:
  58.             return cls._shared_instances[bus_type]
  59.         if bus_type == BUS_SESSION:
  60.             subclass = SessionBus
  61.         elif bus_type == BUS_SYSTEM:
  62.             subclass = SystemBus
  63.         elif bus_type == BUS_STARTER:
  64.             subclass = StarterBus
  65.         else:
  66.             raise ValueError('invalid bus_type %s' % bus_type)
  67.         bus = (bus_type in cls._shared_instances).__new__(subclass, bus_type, mainloop = mainloop)
  68.         bus._bus_type = bus_type
  69.         if not private:
  70.             cls._shared_instances[bus_type] = bus
  71.         
  72.         return bus
  73.  
  74.     
  75.     def close(self):
  76.         t = self._bus_type
  77.         if self.__class__._shared_instances.get(t) is self:
  78.             del self.__class__._shared_instances[t]
  79.         
  80.         super(Bus, self).close()
  81.  
  82.     
  83.     def get_connection(self):
  84.         '''Return self, for backwards compatibility with earlier dbus-python
  85.         versions where Bus was not a subclass of Connection.
  86.  
  87.         :Deprecated: since 0.80.0
  88.         '''
  89.         return self
  90.  
  91.     _connection = property(get_connection, None, None, 'self._connection == self, for backwards\n                           compatibility with earlier dbus-python versions\n                           where Bus was not a subclass of Connection.')
  92.     
  93.     def get_session(private = False):
  94.         '''Static method that returns a connection to the session bus.
  95.  
  96.         :Parameters:
  97.             `private` : bool
  98.                 If true, do not return a shared connection.
  99.         '''
  100.         return SessionBus(private = private)
  101.  
  102.     get_session = staticmethod(get_session)
  103.     
  104.     def get_system(private = False):
  105.         '''Static method that returns a connection to the system bus.
  106.  
  107.         :Parameters:
  108.             `private` : bool
  109.                 If true, do not return a shared connection.
  110.         '''
  111.         return SystemBus(private = private)
  112.  
  113.     get_system = staticmethod(get_system)
  114.     
  115.     def get_starter(private = False):
  116.         '''Static method that returns a connection to the starter bus.
  117.  
  118.         :Parameters:
  119.             `private` : bool
  120.                 If true, do not return a shared connection.
  121.         '''
  122.         return StarterBus(private = private)
  123.  
  124.     get_starter = staticmethod(get_starter)
  125.     
  126.     def __repr__(self):
  127.         if self._bus_type == BUS_SESSION:
  128.             name = 'session'
  129.         elif self._bus_type == BUS_SYSTEM:
  130.             name = 'system'
  131.         elif self._bus_type == BUS_STARTER:
  132.             name = 'starter'
  133.         else:
  134.             name = 'unknown bus type'
  135.         return '<%s.%s (%s) at %#x>' % (self.__class__.__module__, self.__class__.__name__, name, id(self))
  136.  
  137.     __str__ = __repr__
  138.  
  139.  
  140. class SystemBus(Bus):
  141.     '''The system-wide message bus.'''
  142.     
  143.     def __new__(cls, private = False, mainloop = None):
  144.         '''Return a connection to the system bus.
  145.  
  146.         :Parameters:
  147.             `private` : bool
  148.                 If true, never return an existing shared instance, but instead
  149.                 return a private connection.
  150.             `mainloop` : dbus.mainloop.NativeMainLoop
  151.                 The main loop to use. The default is to use the default
  152.                 main loop if one has been set up, or raise an exception
  153.                 if none has been.
  154.         '''
  155.         return Bus.__new__(cls, Bus.TYPE_SYSTEM, mainloop = mainloop, private = private)
  156.  
  157.  
  158.  
  159. class SessionBus(Bus):
  160.     '''The session (current login) message bus.'''
  161.     
  162.     def __new__(cls, private = False, mainloop = None):
  163.         '''Return a connection to the session bus.
  164.  
  165.         :Parameters:
  166.             `private` : bool
  167.                 If true, never return an existing shared instance, but instead
  168.                 return a private connection.
  169.             `mainloop` : dbus.mainloop.NativeMainLoop
  170.                 The main loop to use. The default is to use the default
  171.                 main loop if one has been set up, or raise an exception
  172.                 if none has been.
  173.         '''
  174.         return Bus.__new__(cls, Bus.TYPE_SESSION, private = private, mainloop = mainloop)
  175.  
  176.  
  177.  
  178. class StarterBus(Bus):
  179.     '''The bus that activated this process (only valid if
  180.     this process was launched by DBus activation).
  181.     '''
  182.     
  183.     def __new__(cls, private = False, mainloop = None):
  184.         '''Return a connection to the bus that activated this process.
  185.  
  186.         :Parameters:
  187.             `private` : bool
  188.                 If true, never return an existing shared instance, but instead
  189.                 return a private connection.
  190.             `mainloop` : dbus.mainloop.NativeMainLoop
  191.                 The main loop to use. The default is to use the default
  192.                 main loop if one has been set up, or raise an exception
  193.                 if none has been.
  194.         '''
  195.         return Bus.__new__(cls, Bus.TYPE_STARTER, private = private, mainloop = mainloop)
  196.  
  197.  
  198. if 'DBUS_PYTHON_NO_DEPRECATED' not in os.environ:
  199.     
  200.     class _DBusBindingsEmulation:
  201.         '''A partial emulation of the dbus_bindings module.'''
  202.         
  203.         def __str__(self):
  204.             return '_DBusBindingsEmulation()'
  205.  
  206.         
  207.         def __repr__(self):
  208.             return '_DBusBindingsEmulation()'
  209.  
  210.         
  211.         def __getattr__(self, attr):
  212.             global dbus_bindings
  213.             import dbus.dbus_bindings as m
  214.             dbus_bindings = m
  215.             return getattr(m, attr)
  216.  
  217.  
  218.     dbus_bindings = _DBusBindingsEmulation()
  219.  
  220.